/**
 * MonsterCanvasElement类 代表怪兽
 * @param {Object} options 怪兽的参数
 * @param {string} options.imgSrc 怪兽的图片url
 * @param {string} options.imgDeadSrc 怪兽死亡的图片url
 * @param {boolean} options.dead 怪兽是否死亡
 */
function MonsterCanvasElement(options) {
  options = Object.assign({}, {
    width: 50,
    height: 50,
    vx: 2,
    vy: 50,
    imgSrc: '',
    imgDeadSrc: '',
    dead: false,
  }, options);
  BaseCanvasElement.call(this, options);
  this.imgSrc = options.imgSrc;
  this.imgDeadSrc = options.imgDeadSrc;
  this.image = new Image();
  this.image.src = this.imgSrc;
  this.imageHit = new Image();
  this.imageHit.src = this.imgDeadSrc;
  this.dead = options.dead;
}

inheritPrototype(MonsterCanvasElement, BaseCanvasElement);

/**
 * render方法 将怪兽绘制到指定的context上,绘制结果应该只和实例的属性有关
 * @param {object} context 画布的 context 对象
 */
MonsterCanvasElement.prototype.render = function (context) {
  // 绘制怪兽
  if (!this.dead) {
    context.drawImage(this.image, this.x, this.y, this.width, this.height);
  } else {
    context.drawImage(this.imageHit, this.x, this.y, this.width, this.height);
  }
}